/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import moment from 'moment';
import type { ProColumns } from '@ant-design/pro-table';
import type { TableListItem } from '@/pages/tools/orderManage/index.d';

function getSelectTime() {
  return Array.from({ length: 7 }, (v, k) =>
    moment(new Date()).subtract(k, 'months').format('YYYY-MM'),
  ).map((item) => ({ label: item, value: item })); // eslint-disable-line
}
export const orderStatus = {
  '0': '待受理',
  '1': '未分配',
  '2': '未取件',
  '7': '已完结',
  '8': '已取件',
  '9': '订单完成',
  '-9': '快递员取消',
  '-10': '客户取消',
  '-8': '订单被拒',
  '-7': '订单关闭',
  '-2': '受理失败',
  '-1': '分配失败',
  '-20': '已退款',
};
function getOptions() {
  const options = Object.keys(orderStatus).map((item) => ({
    label: orderStatus[item],
    value: item,
  }));
  return options;
}

const columns: ProColumns<TableListItem>[] = [
  {
    title: '订单号',
    search: false,
    align: 'center',
    dataIndex: 'id',
  },
  {
    title: '运单号',
    search: false,
    align: 'center',
    dataIndex: 'waybill_no',
    fieldProps: {
      placeholder: '请输入运单号',
    },
  },
  {
    title: '订单状态',
    dataIndex: 'status',
    search: false,
    align: 'center',
    fieldProps: {
      placeholder: '请输入运单号',
    },
    renderText: (_, record) => {
      const { status } = record;
      return orderStatus[status];
    },
  },
  {
    title: '发件人',
    dataIndex: 'shipper_name',
    search: false,
    align: 'center',
  },
  {
    title: '联系电话',
    dataIndex: 'shipper_mobile',
    search: false,
    align: 'center',
  },
  {
    title: '受理网点',
    search: false,
    align: 'center',
    dataIndex: 'collect_shop_name',
  },
  {
    title: '创建时间',
    search: false,
    align: 'center',
    dataIndex: 'create_at',
  },
  {
    title: '更新时间',
    search: false,
    align: 'center',
    dataIndex: 'update_at',
  },
];

const orderSource = [
  {
    dataIndex: 'shipper_uid',
    title: '用户id',
  },
  {
    dataIndex: 'shipper_name',
    title: '用户名',
  },
  {
    dataIndex: 'create_at',
    title: '创建时间',
  },
  {
    dataIndex: 'status',
    title: '订单状态',
    renderText: (_: any, value: string) => {
      return orderStatus[value];
    },
  },
  {
    dataIndex: 'brand',
    title: '快递品牌',
  },
  {
    dataIndex: 'collect_shop_name',
    title: '快递网点名称',
  },
  {
    dataIndex: 'waybill_no',
    title: '快递单号',
  },
  {
    dataIndex: 'collect_courier_name',
    title: '业务员名字',
  },
  {
    dataIndex: 'collect_courier_mobile',
    title: '业务员手机',
  },
  {
    dataIndex: 'package_info',
    title: '物品名称',
  },
  {
    dataIndex: 'package_weight',
    title: '预估重量',
  },
  {
    dataIndex: 'charging_weight',
    title: '实际重量',
  },
  {
    dataIndex: 'package_note',
    title: '备注信息',
  },
  {
    dataIndex: 'shipper_name',
    title: '发件人',
  },
  {
    dataIndex: 'shipper_mobile',
    title: '发件人移动电话',
  },
  {
    dataIndex: 'shipper_province',
    title: '发件地址_省',
  },
  {
    dataIndex: 'shipper_city',
    title: '发件地址_市',
  },
  {
    dataIndex: 'shipper_district',
    title: '发件地址_县',
  },
  {
    dataIndex: 'shipper_address',
    title: '发件地址_详细',
  },
  {
    dataIndex: '',
    title: '发件地址_邮编',
  },
  {
    dataIndex: 'shipper_tel',
    title: '发件人固定电话',
  },
  {
    dataIndex: '',
    title: '发件地址id',
  },
  {
    dataIndex: 'reason_fail',
    title: '下单失败原因',
  },
  {
    dataIndex: 'source_name',
    title: '订单类型',
  },
];

const addresseeSource = [
  {
    dataIndex: 'id',
    title: '订单号',
  },
  {
    dataIndex: 'shipping_name',
    title: '收件人',
  },
  {
    dataIndex: 'shipping_mobile',
    title: '收件人移动电话',
  },
  {
    dataIndex: 'shipping_province',
    title: '收件地址_省',
  },
  {
    dataIndex: 'shipping_city',
    title: '收件地址_市',
  },
  {
    dataIndex: 'shipping_district',
    title: '收件地址_县',
  },
  {
    dataIndex: 'shipping_address',
    title: '收件地址_详细',
  },
  {
    dataIndex: '',
    title: '收件地址_邮编',
  },
  {
    dataIndex: 'shipping_tel',
    title: '收件人固定电话',
  },
  {
    dataIndex: '',
    title: '收件地址_id',
  },
  {
    dataIndex: 'channel',
    title: '渠道',
  },
  {
    dataIndex: 'freight',
    title: '应付金额',
  },
  {
    dataIndex: 'receipts_under_custody',
    title: '实付金额',
  },
  {
    dataIndex: 'claiming_value',
    title: '保价金额',
  },
  {
    dataIndex: 'claiming_value_pay',
    title: '保价费',
  },
];

export { columns, orderSource, addresseeSource, getSelectTime, getOptions };
